package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.ProductSort;
import cn.wolfcode.trip.base.mapper.ProductSortMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IProductSortService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/** tiger
 * 商品分类
 */
@Service
public class ProductSortServiceImpl implements IProductSortService {
    @Autowired
    private ProductSortMapper productSortMapper;


    /**
     * 查询全部商品分类(分页)
     * @param qo
     * @return
     */
    public PageInfo<ProductSort> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<ProductSort> list = productSortMapper.selectForList(qo);
        return new PageInfo<>(list);
    }

    /**
     * 保存或更新操作
     * @param productSort
     */
    public void saveOrUpdate(ProductSort productSort) {
        if (productSort.getId()!=null){
            productSortMapper.updateByPrimaryKey(productSort);
        }else{
            productSortMapper.insert(productSort);
        }

    }

    /**
     * 删除操作
     * @param id
     */
    public void delete(Long id) {
        productSortMapper.deleteByPrimaryKey(id);
    }

    /**
     * 查询全部分类
     * @return
     */
    public List<ProductSort> ListAll() {
        return productSortMapper.selectAll();
    }
}
